package com.xdjd.task.service.daoservice;

import com.xdjd.task.mapper.activity.ActivityChallengeRecordDetailPoDao;
import com.xdjd.task.model.activity.ActivityChallengeRecordDetailPo;
import net.oschina.durcframework.easymybatis.query.Query;
import net.oschina.durcframework.easymybatis.query.Sort;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ActivityChallengeRecordDetailPoService {

    @Autowired
    private ActivityChallengeRecordDetailPoDao activityChallengeRecordDetailPoDao;

    public void updateTodayStepByMemberId(Long memberId, Long stepNumber) {
        activityChallengeRecordDetailPoDao.updateTodayStepByMemberId(memberId, stepNumber);
    }

    public void saveRecordDetail(ActivityChallengeRecordDetailPo po) {
        po.setCreateTime(new Date());
        po.setModifyTime(new Date());
        activityChallengeRecordDetailPoDao.save(po);
    }

    public List<ActivityChallengeRecordDetailPo> findByRecordNo(String recordNo) {
        Query query=new Query().eq("record_no",recordNo);
        query.addSort("step_number", Sort.DESC);
        return activityChallengeRecordDetailPoDao.findAll(query);
    }

    public void updateRecordDetail(ActivityChallengeRecordDetailPo po) {
        po.setModifyTime(new Date());
        activityChallengeRecordDetailPoDao.update(po);
    }
}
